#include<iostream>
using namespace std;
#include<unordered_map>
#include<string>
#include<algorithm>
class Solution {
public:
    string rankTeams(vector<string>& votes) {
        unordered_map<char, vector<int>> find;
        int arr[26] = { 0 };
        int n = votes[0].size();
        for (auto& e : votes[0])
            find[e].resize(26,0);
        for (auto& e : votes) {
            for (int i = 0; i < n; ++i) {
                ++find[e[i]][i];
            }
        }
        string ans=votes[0];
        sort(ans.begin(), ans.end(), [&](char a, char b) {return find[a] > find[b] || (find[a] == find[b] && a < b); });
        return ans;
    }
};
int main() {
    vector<string> vec{ "ABC","ACB","ABC","ACB","ACB" };
    Solution().rankTeams(vec);
}